package com.five.dao.impl.backstage;

import com.five.dao.backstage.TuiFangDao;
import com.five.entity.backstage.TuiFang;
import com.five.util.DBUtil;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @ClassName TuiFangDaoImpl
 * @Description TODO
 * @Author yuanshuaiqiang
 * @Date 2020/12/3 15:48
 */
@Repository
public class TuiFangDaoImpl implements TuiFangDao {
    @Override
    public List<Map> queryAll(Integer page, Integer limit, TuiFang tuiFang) {
        String sql="select tf.*,td.name name,tp.name roomname from t_tuifang tf \n" +
                "join t_order td on tf.orderid=td.orderid JOIN\n" +
                "t_type tp on td.roomtype=tp.id where 1=1 ";
        if (tuiFang.getKdate()!=null && tuiFang.getKdate()!="" && tuiFang.getEdate()!=null && tuiFang.getEdate()!=""){
            sql+=" and tf.outdate>'"+tuiFang.getKdate()+"' and tf.outdate<'"+tuiFang.getEdate()+"' ";
        }
        sql+=" limit ?,? ";
        List<Map> maps = DBUtil.queryMap(sql,(page-1)*limit,limit);
        return maps;
    }

    @Override
    public int getcount(TuiFang tuiFang) {
        String sql="select count(*)a from t_tuifang tf \n" +
                "join t_order td on tf.orderid=td.orderid JOIN\n" +
                "t_type tp on td.roomtype=tp.id where 1=1 ";

        if (tuiFang.getKdate()!=null && tuiFang.getKdate()!="" && tuiFang.getEdate()!=null && tuiFang.getEdate()!=""){
            sql+=" and tf.outdate>'"+tuiFang.getKdate()+"' and tf.outdate<'"+tuiFang.getEdate()+"' ";
        }

        List<Map> maps = DBUtil.queryMap(sql);
        String s = maps.get(0).get("a") + "";
        int i = Integer.parseInt(s);
        return i;
    }
}
